/*
 * This source code is part of TWaver 4.0
 *
 * Serva Software PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 * Copyright 2002 - 2011 Serva Software. All rights reserved.
 */

package demo.network.miscellaneous.instrument.elementui;

import java.awt.Color;
import java.awt.Graphics2D;

import demo.network.miscellaneous.instrument.element.Thermometer;

import twaver.TWaverConst;
import twaver.network.TNetwork;
import twaver.network.ui.NodeUI;

public class ThermometerUI extends NodeUI {

    public ThermometerUI(TNetwork network, Thermometer thermometer) {
        super(network, thermometer);
    }

    public Thermometer getThermometer(){
    	return (Thermometer)this.getElement();
    }
    
    public void paintBody(Graphics2D g2d) {
        super.paintBody(g2d);
        
        int percentage = getThermometer().getPercentage();
        percentage = percentage < 0 ? 0 : percentage;
        percentage = percentage > 100 ? 100 : percentage;

        if (percentage >= 0) {
            g2d.setStroke(TWaverConst.DOUBLE_WIDTH_STROKE);
            g2d.setColor(Color.red);
            int height = getThermometer().getHeight()-20;
            int width = getThermometer().getWidth();
            int x = getThermometer().getLocation().x;
            int y = getThermometer().getLocation().y + 4;
            float value = (float) percentage / 100;
            value = height * value;
            g2d.drawLine(x + width / 2,
                         y + height,
                         x + width / 2,
                         y + (height - (int) value));
        }
    }

}